package com.framwork.core.base;

import com.framwork.core.FeiShuAPIClientBuilder;
import com.framwork.core.api.accessToken.input.OpenApisAuthV3AppAccessTokenInternalInput;
import com.framwork.core.api.accessToken.result.OpenApisAuthV3AppAccessTokenInternalResult;
import com.framwork.core.config.APIClientConfiguration;

import java.util.Objects;

/**
 * @author ：james.liu
 * @date ：Created in 2022/2/17 8:50
 * @description：
 * @version: 1.0
 */
public interface AbstractDefaultAPIActionProxy {

    /**
     * 提供一个默认获取token的方法
     *
     * @return
     * @throws Exception
     */
    default String getAccessToken() throws Exception {
        OpenApisAuthV3AppAccessTokenInternalInput input = new OpenApisAuthV3AppAccessTokenInternalInput();
        OpenApisAuthV3AppAccessTokenInternalResult result =
                FeiShuAPIClientBuilder.getInstance().build().getAccessTokenClient().OpenApisAuthV3AppAccessTokenInternal(input);
        if (Objects.isNull(result)) {
            return null;
        }
        return result.getApp_access_token();
    }

    /**
     * 获取请求接口
     *
     * @param configuration
     * @param cmdId
     * @return
     */
    default String getUrl(final APIClientConfiguration configuration, String cmdId) {
        return configuration.getApiUrl() + cmdId;
    }
}
